
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>垃圾收集有哪些算法，各自的特点？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>垃圾收集有哪些算法，各自的特点？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">标记-清除 (Mark-Sweep) 算法包含哪两个核心阶段？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">标记-清除算法包含两个核心阶段：1. 标记阶段，从 GC Roots 开始标记所有可达对象。2. 清除阶段，遍历整个堆，回收所有未被标记的不可达对象。</div>
          </div>
          <div class="card-source">来源: 1. 标记-清除算法（Mark-Sweep）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">标记-清除 (Mark-Sweep) 算法存在哪些主要缺点？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">该算法的主要缺点有两个：一是回收后会留下不连续的内存空间，导致“内存碎片”问题；二是整个回收过程会暂停应用程序，产生较长的“停顿时间”。</div>
          </div>
          <div class="card-source">来源: 1. 标记-清除算法（Mark-Sweep）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">标记-整理 (Mark-Compact) 算法是如何解决标记-清除算法的内存碎片问题的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">标记-整理算法通过增加一个“整理阶段”来解决内存碎片问题。在该阶段，它会将所有被标记的存活对象移动到内存的一端，然后统一清除边界之外的内存区域。</div>
          </div>
          <div class="card-source">来源: 2. 标记-整理算法（Mark-Compact）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">复制 (Copying) 算法虽然高效，但它的主要代价是什么？它通常被用于哪个内存区域？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">复制算法的主要代价是需要额外的内存空间来存放对象的副本，导致较高的内存消耗。由于新生代对象生命周期短、回收频繁的特点，该算法通常用于年轻代。</div>
          </div>
          <div class="card-source">来源: 3. 复制算法（Copying）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">分代收集 (Generational Collection) 算法的基本思想是什么？它如何为不同区域选择回收策略？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">基本思想是将不同生命周期的对象分开处理以提高效率。它将堆分为年轻代和老年代：年轻代存放新对象，使用回收效率高的复制算法；老年代存放存活时间长的对象，使用标记-清除或标记-整理算法。</div>
          </div>
          <div class="card-source">来源: 4. 分代收集算法（Generational Collection）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">CMS (并发标记-清除) 收集器是如何实现其“减少停顿时间”这一主要目标的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">CMS 通过将垃圾回收过程中的“并发标记”和“并发清除”阶段与应用程序并发执行，从而极大地减少了需要暂停应用程序的时间。只有在“初始标记”和“重新标记”阶段需要短暂的停顿。</div>
          </div>
          <div class="card-source">来源: 5. 并发标记-清除算法（Concurrent Mark-Sweep, CMS）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">G1 (Garbage-First) 垃圾收集器相比于 CMS 有哪些关键优势？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">G1 的关键优势在于它通过精细控制回收过程实现了低延迟，并且在回收的同时进行整理，解决了 CMS 可能会产生的内存碎片问题。</div>
          </div>
          <div class="card-source">来源: 6. Garbage-First (G1) 垃圾收集器</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">ZGC (Z Garbage Collector) 最突出的特点是什么？这使得它特别适用于哪类应用？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">ZGC 最突出的特点是其极低的延迟和几乎零停顿时间，这是通过并发标记和并发整理实现的。它特别适用于对停顿时间有极高要求的大规模内存应用。</div>
          </div>
          <div class="card-source">来源: 7. Z Garbage Collector (ZGC)</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Shenandoah 垃圾收集器与 ZGC 有什么相似之处？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Shenandoah 与 ZGC 类似，都是通过并发方式进行垃圾回收的。它同样能并发地进行标记、清除和整理操作，其设计目标也是为了实现低停顿时间，适用于低延迟应用。</div>
          </div>
          <div class="card-source">来源: 8. Shenandoah Garbage Collector</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
